<include file="Public/head" />
<style type="text/css">
    .chip table tr{height:82px;}
    .chip table tr td input {width:360px;height:30px;line-height:30px;border:1px solid #ececec;}
    .chip #chip_content{width:360px;height:160px;resize: none;border:1px solid #ececec;font-size:14px;}
    .shangchuan{position: relative;overflow: hidden;display:inline-block;*display:inline;padding:4px 10px 4px;font-size:14px;line-height:18px;*line-height:20px;color:#fff;text-align:center;vertical-align:middle;cursor:pointer;background-color:#5bb75b;border:none;border-color:#e6e6e6 #e6e6e6 #bfbfbf;border-bottom-color:#b3b3b3;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px;}
    .shangchuan input {position: absolute;top: 0; right: 0;margin: 0;border:none;opacity: 0;filter:alpha(opacity=0); cursor: pointer;}
</style>
<script type="text/javascript" src="/static/js/jquery.form.js"></script>
<script src="{:get_style_cdnurl()}paimai/yunying/js/city.js" type="text/javascript"></script>
</head>
<body>
<include file="Public/common_header" />
<div class="mian">
    <include file="Public/sidebar"  menu="clcwht.clcwspgl" />
    <div class="mianR">
        <h3 class="cha">添加碎片</h3>
        <div class="chip">
            <table width="100%">
                <tr>
                    <td width="20%">*碎片标识</td>
                    <td width="80%">
                        <input type="text" id="name" name="name" value="" placeholder="请输入碎片标识">
                    </td>
                </tr>
                <tr>
                    <td>*碎片描述</td>
                    <td>
                        <input type="text" id="desc" name="desc" value="" placeholder="请输入碎片描述">
                    </td>
                </tr>
                <tr>
                    <td>*碎片内容</td>
                    <td>
                        <textarea name="chip_content" id="chip_content" placeholder="请输入碎片内容"></textarea>
                    </td>
                </tr>
                <tr>  
                    <td>*内容是否json格式</td>
                    <td>                    
                        <input type="radio" name="json_type" value="1" style="width:50px;height:15px">是
                        <input type="radio" name="json_type" value="2" checked="checked" style="width:50px;height:15px">否
                    </td>
                </tr>
                <tr>
                    <td>
                        <form id='myupload' action='/ClcwChip/addFile' method='post' enctype='multipart/form-data'>
                            <div class="shangchuan">
                            <span>上传</span>
                            <input id="fileupload" type="file" name="pic" onchange="upload_file(this);">
                        </div>
                        </form>
                    </td>
                    <td id="url">                    
                        
                    </td>
                </tr>
            </table>
            <div class="yongBtn">
                <input type="button" value="确定"  class="queding"/>
                <input type="button" value="取消" class="quxiao" onclick="history.back()">
            </div>
        </div>
    </div>
    <div class="clear"></div>
    <script type="text/javascript">
        $(".queding").click(function(){
            var btn_obj = $(this);
            var name = $("#name").val();
            var desc = $("#desc").val();
            var json_type = $('input[name="json_type"]:checked ').val();
            var chip_content = $("#chip_content").val();
            var params = {
                'name':name,
                'desc':desc,
                'json_type':json_type,
                'content':chip_content
            }
            $.post("{:U('/ClcwChip/addClcwChipData')}", params, function (data) {
                if (data.code != 200) {
                    shibai_alert(data.msg, 1500);
                    return false;
                }
                btn_alert("添加成功", 1500, function () {
                    location.href = "{:U('/ClcwChip/index')}";
                });
            }, "json");
        })

    function upload_file(obj){
        var btn = $(obj).siblings("span");
        $("#myupload").ajaxSubmit({
            dataType:  'json',
            beforeSend: function() {
                btn.html("上传中...");
                $(obj).attr('type','botton');
                $(obj).parent().css("background-color","#b3b3b3");
            },
            success: function(data) {
                if (data.code == 200) {
                    // console.log(data.data);
                    btn.html("上传");
                    $(obj).attr('type','file');
                    $(obj).parent().css("background-color","#5bb75b");
                    $('#url').html(data.data);
                }else{
                    btn.html("上传");
                    $(obj).attr('type','file');
                    $(obj).parent().css("background-color","#5bb75b");
                    shibai_alert(data.msg,2000);
                }
            },
            error:function(xhr){
                // btn.html("上传失败");
                // files.html(xhr.responseText);
                // console.log(xhr.responseText);
                // xhr.responseText = "图片过大";
                btn.html("上传");
                $(obj).attr('type','file');
                $(obj).parent().css("background-color","#5bb75b");
                //shibai_alert(xhr.responseText,2000);
            },
            clearForm: true   
        });
    }

    </script>
    <include file="Public/foot" />
